#include <iostream>
#include <istream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;

bool noCaseEqu(char a, char b){
	return (a == b) || (a+32 == b) || (a == b+32);
}

class Board{
	int rows, cols;
	vector< vector<char> > data;
	vector<string> words;
	vector<string> locations;

	public:
	Board() {}

	bool isWordPresent(int x, int y, int xDir, int yDir, string word){
		if(word == "")
			return true;
		if(x < 0 || y < 0 || x >= rows || y >= cols)
			return false;

		if(noCaseEqu(data[x][y], word[0]))
			return isWordPresent(x+xDir, y+yDir, xDir, yDir, word.substr(1, word.size()));
		else
			return false;
	}

	void searchForWord(string word){
		for(int x = 0; x < rows; ++x){
			for(int y = 0; y < cols; ++y){				//for all chars in the 2D array
				for(int xDir = -1; xDir <= 1; xDir++){
					for(int yDir = -1; yDir <= 1; yDir++){	//for all directions
						if (isWordPresent(x,y,xDir,yDir,word)){
							ostringstream s;
							s << x+1 << " " << y+1;
							locations.push_back(s.str());
							return;
						}
					}
				}
			}
		}
	}

	void findWords(){
		for(size_t wc = 0; wc < words.size(); ++wc){			//for all words
			searchForWord(words[wc]);
		}
	}
	friend istream& operator>>(istream& is, Board& b);
	friend ostream& operator<<(ostream& os, const Board& b);
	friend ostream& operator<(ostream& os, const Board& b);
};

istream& operator>>(istream& is, Board& b){
	//read x & y
	is >> b.rows >> b.cols;
	//read grid
	for(int x = 0; x < b.rows; ++x){
		vector<char> tempVec;
		for(int y = 0; y < b.cols; ++y){
			char c;
			is >> c;
			tempVec.push_back(c);
		}
		b.data.push_back(tempVec);
	}
	//read word #
	int end;
	is >> end;
	//read words
	for(int i = 0; i < end; ++i){
		string tmpWord;
		is >> tmpWord;
		b.words.push_back(tmpWord);
	}
	return is;
}

ostream& operator<(ostream& os, const Board& b){ // this is a more useful statement but I figured I would use the wierd non-standard output operator for the non-critical one
	os << b.rows << " " << b.cols << endl;

	for(int x = 0; x < b.rows; ++x){
		for(int y = 0; y < b.cols; ++y)
			os << b.data[x][y];
		os << endl;
	}

	os << b.words.size() << endl;

	for(size_t i = 0; i < b.words.size(); ++i)
		os << b.words[i] << endl;
	return os;
}


ostream& operator<<(ostream& os, const Board& b){ // statement for UVa
	for(size_t i = 0; i < b.locations.size(); ++i)
		os << b.locations[i] << endl;
	return os;
}

int main(){
	int cases;
	cin >> cases;
	for(int i = 0; i < cases; ++i){
		Board board;
		cin >> board;
		board.findWords();
		cout << board; //YES THIS IS VALIDi
		if(i != cases-1) 
			cout << endl;
	}
}
